package com.eshop.modules.shop.service.impl;

import java.io.IOException;
import java.util.Iterator;
import com.eshop.utils.FileUtil;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.eshop.common.utils.QueryHelpPlus;
import com.eshop.modules.shop.service.dto.SystemStoreStaffDto;
import java.util.LinkedHashMap;
import java.util.List;
import com.github.pagehelper.PageInfo;
import java.util.Map;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.shop.service.dto.SystemStoreStaffQueryCriteria;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.eshop.enums.ShopCommonEnum;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.shop.service.SystemStoreStaffService;
import com.eshop.modules.shop.domain.SystemStoreStaff;
import com.eshop.modules.shop.service.mapper.SystemStoreStaffMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class SystemStoreStaffServiceImpl extends BaseServiceImpl<SystemStoreStaffMapper, SystemStoreStaff> implements SystemStoreStaffService
{
    private final IGenerator generator;
    
    public boolean checkStatus(final Long uid, final Integer storeId) {
        final SystemStoreStaff storeStaff = new SystemStoreStaff();
        storeStaff.setUid(uid);
        storeStaff.setVerifyStatus(ShopCommonEnum.IS_STATUS_1.getValue());
        if (storeId != null) {
            storeStaff.setStoreId(storeId);
        }
        return ((SystemStoreStaffMapper)this.baseMapper).selectCount((Wrapper)Wrappers.query((Object)storeStaff)) > 0;
    }
    
    public Map<String, Object> queryAll(final SystemStoreStaffQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<SystemStoreStaff> page = (PageInfo<SystemStoreStaff>)new PageInfo((List)this.queryAll(criteria));
        final Map<String, Object> map = new LinkedHashMap<String, Object>(2);
        map.put("content", this.generator.convert(page.getList(), (Class)SystemStoreStaffDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }
    
    public List<SystemStoreStaff> queryAll(final SystemStoreStaffQueryCriteria criteria) {
        return (List<SystemStoreStaff>)((SystemStoreStaffMapper)this.baseMapper).selectList((Wrapper)QueryHelpPlus.getPredicate((Object)SystemStoreStaff.class, (Object)criteria));
    }
    
    public void download(final List<SystemStoreStaffDto> all, final HttpServletResponse response) throws IOException {
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (final SystemStoreStaffDto yxSystemStoreStaff : all) {
            final Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("微信用户id", yxSystemStoreStaff.getUid());
            map.put("店员头像", yxSystemStoreStaff.getAvatar());
            map.put("门店id", yxSystemStoreStaff.getStoreId());
            map.put("店员名称", yxSystemStoreStaff.getStaffName());
            map.put("手机号码", yxSystemStoreStaff.getPhone());
            map.put("核销开关", yxSystemStoreStaff.getVerifyStatus());
            map.put("状态", yxSystemStoreStaff.getStatus());
            map.put("微信昵称", yxSystemStoreStaff.getNickname());
            map.put("所属门店", yxSystemStoreStaff.getStoreName());
            list.add(map);
        }
        FileUtil.downloadExcel((List)list, response);
    }
    
    public SystemStoreStaffServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
